-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(block): add command line executor block #2745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Conversation
|
@jgranesa is attempting to deploy a commit to the Sim Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
Summary
This PR adds a new command execution feature to the Sim application, allowing workflows to execute bash commands through a new block and tool. The implementation includes:
- New API Route:
/api/tools/command/exec/route.ts- Handles command execution with timeout and shell configuration - Block Definition:
command.ts- Provides the UI block for users to configure command execution - Tool Configuration:
tools/command/- Defines the tool interface and types - Registry Updates: Both block and tool registries updated to include the new command executor
Issues Found
Critical Security Issues
-
Missing Authentication: The API route lacks authentication checks. Other tool routes in the codebase use
getSession()to verify user identity before executing operations. Command execution is a sensitive operation that must be restricted to authenticated users only. -
Missing Input Validation: The
workingDirectoryandshellparameters are not validated:workingDirectorycould contain path traversal sequencesshellparameter accepts any arbitrary value instead of being restricted to a whitelist- The codebase has established validation patterns using
validatePathSegment()from/lib/core/security/input-validationthat should be used here
Code Quality Issues
-
Inconsistent Logging: Uses
console.errorinstead of thecreateLoggerpattern used throughout the codebase. Global standards require using@sim/logger. -
Missing Output Schema: The tool configuration in
chat.tsdoesn't define theoutputsfield, which other similar tools include for documentation and type safety.
Positive Aspects
- Block definition is well-structured with proper subBlocks, parameters, and I/O definitions
- Type definitions are clear with good JSDoc documentation
- Proper integration with block and tool registries
- Correct use of lucide-react icons consistent with other blocks
- Good timeout and signal handling logic (SIGTERM → SIGKILL fallback)
Recommendations
- Add authentication check using
getSession() - Validate
workingDirectorywithvalidatePathSegment()andallowDots: true - Add whitelist validation for
shellparameter - Replace
console.errorwith structured logging usingcreateLogger - Add
outputsschema definition to tool configuration
Confidence Score: 2/5
- This PR introduces critical security vulnerabilities that must be fixed before merging. The command execution endpoint lacks authentication and input validation, creating significant risk.
- The low confidence score reflects two critical security issues: (1) Missing authentication allows unauthenticated users to execute arbitrary commands on the server, and (2) Lack of input validation on shell and working directory parameters could enable injection attacks or path traversal. These are not best-practice issues but actual security vulnerabilities that would allow attackers to execute arbitrary code. The route handling and block definitions are otherwise well-implemented, but the security gaps overshadow this. Additional code quality issues (logging, missing output schema) are secondary to the critical security problems.
- The primary file requiring attention is
apps/sim/app/api/tools/command/exec/route.ts, which must be updated with: (1) authentication check viagetSession(), (2) input validation forworkingDirectoryandshellparameters, and (3) proper logging using createLogger. Theapps/sim/tools/command/chat.tsfile should have output schema added for consistency with similar tools.
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| apps/sim/app/api/tools/command/exec/route.ts | 2/5 | API route for command execution with multiple critical issues: missing authentication check, inconsistent logging (console.error instead of logger), and no input validation on workingDirectory and shell parameters. Spawns shell processes with user input which requires proper validation. Missing environment variable sanitization and error handling consistency. |
| apps/sim/tools/command/chat.ts | 3/5 | Tool configuration for command execution is mostly correct but missing outputs definition. Tool config follows patterns from other tools (request, params, body functions) but lacks the outputs schema that describes the response structure. |
| apps/sim/blocks/blocks/command.ts | 4/5 | Block definition is well-structured with proper subBlocks, tool config, and I/O definitions. Uses lucide-react Terminal icon which is consistent with other blocks. Parameter transformation in tool config correctly converts timeout to number. No issues found. |
Sequence Diagram
sequenceDiagram
participant User as User/Workflow
participant Block as Command Block
participant Tool as Tool Config
participant API as /api/tools/command/exec
participant Executor as Shell Executor
participant Process as Child Process
User->>Block: Configure command parameters
Block->>Tool: Transform and prepare request
Tool->>API: POST request with command, workingDirectory, shell, timeout
Note over API: ⚠️ Missing: Authentication check
Note over API: ⚠️ Missing: Input validation
API->>Executor: executeCommand(command, cwd, timeout, shell)
Executor->>Process: spawn(shell, ["-c", command])
Process-->>Executor: stdout/stderr data
Executor->>Executor: Set timeout handler (SIGTERM → SIGKILL)
Process-->>Executor: close event with exit code
Executor-->>API: ExecutionResult (stdout, stderr, exitCode, timedOut)
API-->>Tool: NextResponse.json(CommandOutput)
Tool-->>Block: Response data
Block-->>User: Display results
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
add authentication check using session Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Summary
Brief description of what this PR does and why.
Fixes #(issue)
Type of Change
Testing
How has this been tested? What should reviewers focus on?
Checklist
Screenshots/Videos